package org.test.jspdb.utils;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Type;

import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

public class JqueryProcess {

	public static String processReturnJson(HttpServletResponse response, Object object) throws IOException {
		Gson g = new Gson();
		String json = g.toJson(object);
		response.setContentType("application/json;charset=utf-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter pw;
		pw = response.getWriter();
		pw.print(json);
		pw.flush();
		pw.close();

		return null;
	}
	
    public static String processReturnJson(HttpServletResponse response, Object object, Type type) throws IOException {
        Gson g = new Gson();
        String json = g.toJson(object, type);
        response.setContentType("application/json;charset=utf-8");
        response.setHeader("Cache-Control", "no-cache");
        PrintWriter pw;
        pw = response.getWriter();
        pw.print(json);
        pw.flush();
        pw.close();

        return null;
    }
}